{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 基于物品的协同过滤\n",
    "- 计算物品->用户的矩阵\n",
    "- 计算物品同现矩阵\n",
    "- 计算物品的协同过滤矩阵\n",
    "- 计算用户浏览过物品的相近物品"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_user_click(rating_file):\n",
    "    \"\"\"\n",
    "    get user clcik list\n",
    "    Args:\n",
    "        rating_file:input_file\n",
    "    Return:\n",
    "        dict,key:userid,value:[item1,item2]\n",
    "    \"\"\"\n",
    "    fp = open(rating_file)\n",
    "    num=0\n",
    "    user_click={}\n",
    "    for line in fp:\n",
    "        items = line.strip().split(\"::\")\n",
    "        uid = items[0]\n",
    "        mid = items[1]\n",
    "        rating = items[2]\n",
    "        if float(rating)<3.0:\n",
    "            continue\n",
    "        if uid not in user_click:\n",
    "            user_click[uid]=[]\n",
    "        user_click[uid].append(mid)\n",
    "    return user_click"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "user_click = get_user_click(\"ml-1m/ratings.dat\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['1193', '661', '914', '3408', '2355', '1197', '1287', '2804', '594', '919', '595', '938', '2398', '2918', '1035', '2791', '2687', '2018', '3105', '2797', '2321', '720', '1270', '527', '2340', '48', '1097', '1721', '1545', '745', '2294', '3186', '1566', '588', '1907', '783', '1836', '1022', '2762', '150', '1', '1961', '1962', '2692', '260', '1028', '1029', '1207', '2028', '531', '3114', '608', '1246']\n"
     ]
    }
   ],
   "source": [
    "print(user_click[\"1\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "import codecs\n",
    "def get_item_info(item_file):\n",
    "    \"\"\"\n",
    "    get item info[title,genres]\n",
    "    Args:\n",
    "        item_file:input iteminfo file\n",
    "    Return:\n",
    "        a dict,key itemid,value:[title,genres]\n",
    "    \n",
    "    \"\"\"\n",
    "    fp = codecs.open(item_file,'r',encoding = \"ISO-8859-1\")\n",
    "    item_info = {}\n",
    "    for line in fp:\n",
    "        items = line.strip().split(\"::\")\n",
    "        if items[0] not in item_info:\n",
    "            item_info[items[0]]=[items[1],items[2]]\n",
    "    return item_info        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Toy Story (1995)', \"Animation|Children's|Comedy\"]\n",
      "3883\n"
     ]
    }
   ],
   "source": [
    "item_info = get_item_info(\"ml-1m/movies.dat\")\n",
    "print(item_info[\"1\"])\n",
    "print(len(item_info))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "def base_contribute_score():\n",
    "    return 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 同现矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "co_appear={}\n",
    "item_user_click_times={}\n",
    "for user,itemlist in user_click.items():\n",
    "    for index_i in range(0,len(itemlist)):\n",
    "        itemid_i = itemlist[index_i]\n",
    "        item_user_click_times.setdefault(itemid_i,0)\n",
    "        item_user_click_times[itemid_i]+=1\n",
    "        for index_j in range(index_i+1,len(itemlist)):\n",
    "            itemid_j = itemlist[index_j]\n",
    "            co_appear.setdefault(itemid_i,{})\n",
    "            co_appear.setdefault(itemid_j,{})\n",
    "            co_appear[itemid_i].setdefault(itemid_j,0)\n",
    "            co_appear[itemid_j].setdefault(itemid_i,0)\n",
    "            co_appear[itemid_i][itemid_j] += base_contribute_score()\n",
    "            co_appear[itemid_j][itemid_i] += base_contribute_score()  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 协同矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "import operator\n",
    "item_sim_score = {}\n",
    "item_sim_score_sorted = {}\n",
    "for itemid_i,relate_item in co_appear.items():\n",
    "    for itemid_j,co_time in relate_item.items():\n",
    "        item_sim_score.setdefault(itemid_i,{})\n",
    "        item_sim_score[itemid_i].setdefault(itemid_j,0)\n",
    "        item_sim_score[itemid_i][itemid_j] = co_time/math.sqrt(item_user_click_times[itemid_j]*item_user_click_times[itemid_i])\n",
    "for itemid in item_sim_score:\n",
    "    item_sim_score_sorted[itemid] = sorted(item_sim_score[itemid].items(),key=operator.itemgetter(1),reverse=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('3114', 0.612198986396246),\n",
       " ('1265', 0.6020552572377078),\n",
       " ('588', 0.5864099493225665),\n",
       " ('2355', 0.5636653032685426),\n",
       " ('1270', 0.5621910172151441),\n",
       " ('34', 0.5557245119336681),\n",
       " ('356', 0.5519724544797965),\n",
       " ('2571', 0.5475094878419099),\n",
       " ('1197', 0.5456439805070591),\n",
       " ('1196', 0.5453601357295754),\n",
       " ('260', 0.5417689303413047),\n",
       " ('1580', 0.5370068532804573),\n",
       " ('364', 0.5353508971603382),\n",
       " ('2396', 0.5314178019722807),\n",
       " ('1198', 0.5251892001135321),\n",
       " ('318', 0.5246436043420603),\n",
       " ('457', 0.5232761005270472),\n",
       " ('2028', 0.5227149935356792),\n",
       " ('1923', 0.5185523751963246),\n",
       " ('589', 0.5173900916860414),\n",
       " ('2716', 0.5169503737615713),\n",
       " ('593', 0.5162910469455431),\n",
       " ('1210', 0.5144454168252343),\n",
       " ('2797', 0.514134978711599),\n",
       " ('1097', 0.513079173099724),\n",
       " ('2918', 0.5119410401913249),\n",
       " ('2762', 0.5105234293426275),\n",
       " ('595', 0.5080682368868706),\n",
       " ('296', 0.5062175003251744),\n",
       " ('1136', 0.505590482794552),\n",
       " ('480', 0.5052767559297423),\n",
       " ('608', 0.5010072099061046),\n",
       " ('2858', 0.500756357229254),\n",
       " ('3253', 0.5005163664302258),\n",
       " ('1784', 0.49761751769441337),\n",
       " ('919', 0.49433273054173593),\n",
       " ('2321', 0.49226522099488934),\n",
       " ('1240', 0.49067480396809987),\n",
       " ('527', 0.4899705216599283),\n",
       " ('1517', 0.4881260269814371),\n",
       " ('1641', 0.48789023893279687),\n",
       " ('1291', 0.48768202463484234),\n",
       " ('1307', 0.48650967211612767),\n",
       " ('39', 0.48529153171463374),\n",
       " ('1394', 0.4841816495857824),\n",
       " ('3255', 0.4838356474351401),\n",
       " ('2174', 0.48274409232941984),\n",
       " ('110', 0.4820388939145126),\n",
       " ('1610', 0.48159705957187876),\n",
       " ('2081', 0.4791010300304539),\n",
       " ('1500', 0.47686614683985334),\n",
       " ('1036', 0.47508680278665544),\n",
       " ('50', 0.47172367173702895),\n",
       " ('1704', 0.4711691142515593),\n",
       " ('2987', 0.4710748629249397),\n",
       " ('1079', 0.47034045777774985),\n",
       " ('1617', 0.4699436762246401),\n",
       " ('2997', 0.4698110369659119),\n",
       " ('1259', 0.4690613163740094),\n",
       " ('2791', 0.4688348494034252),\n",
       " ('2000', 0.46865082447902756),\n",
       " ('1073', 0.4664717840310534),\n",
       " ('2916', 0.46614409097384474),\n",
       " ('150', 0.4635448915119506),\n",
       " ('1968', 0.463426909392847),\n",
       " ('380', 0.4615870445333369),\n",
       " ('590', 0.4613272565465615),\n",
       " ('377', 0.4610671003362555),\n",
       " ('367', 0.45777653750358377),\n",
       " ('2302', 0.45751942900411485),\n",
       " ('1393', 0.457384923803794),\n",
       " ('3175', 0.45738254377337195),\n",
       " ('2628', 0.45329726138474735),\n",
       " ('32', 0.4531983322163702),\n",
       " ('592', 0.4525663870211249),\n",
       " ('1278', 0.45219743197249307),\n",
       " ('551', 0.4520863284057763),\n",
       " ('2804', 0.4513652846144005),\n",
       " ('1200', 0.45128015585638975),\n",
       " ('357', 0.4498001332346447),\n",
       " ('21', 0.4496213252277799),\n",
       " ('1214', 0.4490731195102493),\n",
       " ('1584', 0.44867242693105935),\n",
       " ('440', 0.4454845113296529),\n",
       " ('1387', 0.44413716606229575),\n",
       " ('3421', 0.4431093297778786),\n",
       " ('1028', 0.44157199111466344),\n",
       " ('780', 0.44154153090366016),\n",
       " ('858', 0.44047866944631303),\n",
       " ('1220', 0.43934738579161847),\n",
       " ('1282', 0.4382112080614779),\n",
       " ('3361', 0.4368301164516187),\n",
       " ('1682', 0.4362050451767289),\n",
       " ('3751', 0.4354305394681838),\n",
       " ('1777', 0.4347842258377402),\n",
       " ('3448', 0.4346670039688434),\n",
       " ('2406', 0.43451567761360427),\n",
       " ('223', 0.43410153506560534),\n",
       " ('1148', 0.4336222530753794),\n",
       " ('733', 0.433369531538181),\n",
       " ('587', 0.4330279916188141),\n",
       " ('648', 0.4329559096168236),\n",
       " ('2291', 0.43228152305540113),\n",
       " ('594', 0.4322533962684074),\n",
       " ('2599', 0.4317147809039197),\n",
       " ('541', 0.43000283606551976),\n",
       " ('2700', 0.42904942824293457),\n",
       " ('3671', 0.42873492047010264),\n",
       " ('3396', 0.4281820349716505),\n",
       " ('1213', 0.4277578783702727),\n",
       " ('2080', 0.42742140181133675),\n",
       " ('2100', 0.42709733776076164),\n",
       " ('539', 0.425495024310135),\n",
       " ('500', 0.4243270505764559),\n",
       " ('597', 0.4227008972845),\n",
       " ('3471', 0.421666220779807),\n",
       " ('2268', 0.42151095542508726),\n",
       " ('2078', 0.42005643787857394),\n",
       " ('3578', 0.4187074235822045),\n",
       " ('47', 0.4184538905740815),\n",
       " ('1396', 0.41673610257249627),\n",
       " ('1089', 0.41666037410214424),\n",
       " ('11', 0.41641388165301757),\n",
       " ('1374', 0.414326460931956),\n",
       " ('2890', 0.4122602518844653),\n",
       " ('1234', 0.4114721600806071),\n",
       " ('1288', 0.4114694420336062),\n",
       " ('2012', 0.4103620674864065),\n",
       " ('1266', 0.40959999011075937),\n",
       " ('1527', 0.4095328438240924),\n",
       " ('1356', 0.40948781680148133),\n",
       " ('3418', 0.40910118495007936),\n",
       " ('3526', 0.40906724472817996),\n",
       " ('1304', 0.40842498308865344),\n",
       " ('2640', 0.408135125183489),\n",
       " ('2324', 0.40765582590572796),\n",
       " ('2011', 0.4058397249567139),\n",
       " ('3039', 0.405024760132514),\n",
       " ('1961', 0.4049926925228216),\n",
       " ('1954', 0.40493114324441726),\n",
       " ('1721', 0.4047089943141123),\n",
       " ('2115', 0.4043706920211412),\n",
       " ('2294', 0.4031173093063464),\n",
       " ('924', 0.4020610167928368),\n",
       " ('1370', 0.3999154469753061),\n",
       " ('3210', 0.39819129014780275),\n",
       " ('1573', 0.3981361718652523),\n",
       " ('1294', 0.3977358167229929),\n",
       " ('2915', 0.39766363127191257),\n",
       " ('3147', 0.3974336657599721),\n",
       " ('1080', 0.3971706451110743),\n",
       " ('1127', 0.39693358398661993),\n",
       " ('2395', 0.3969207055718156),\n",
       " ('2194', 0.3968892804264575),\n",
       " ('3108', 0.39560235400448207),\n",
       " ('1747', 0.3950413485997873),\n",
       " ('3793', 0.3948161039300062),\n",
       " ('2470', 0.3946433574396615),\n",
       " ('1225', 0.39460730527086585),\n",
       " ('1222', 0.3943875356032473),\n",
       " ('1358', 0.39414149455556746),\n",
       " ('235', 0.3938587257681959),\n",
       " ('2108', 0.39328924651554736),\n",
       " ('2248', 0.3929418521914413),\n",
       " ('1485', 0.3929126389928706),\n",
       " ('3052', 0.3921640093765591),\n",
       " ('1907', 0.39202115619880673),\n",
       " ('1663', 0.39157893346727835),\n",
       " ('141', 0.3905827679873354),\n",
       " ('1242', 0.3899375963611511),\n",
       " ('3552', 0.38908018739862404),\n",
       " ('1193', 0.38897338934565645),\n",
       " ('1101', 0.38869439580901255),\n",
       " ('1258', 0.38851681109058844),\n",
       " ('2959', 0.387657928752619),\n",
       " ('2407', 0.3873699703070328),\n",
       " ('1285', 0.38675694277496364),\n",
       " ('2054', 0.3862994599106666),\n",
       " ('3363', 0.3856340332425766),\n",
       " ('2144', 0.3852902318819686),\n",
       " ('1029', 0.3848902491307996),\n",
       " ('2353', 0.384817539070107),\n",
       " ('1221', 0.38397069879998114),\n",
       " ('1377', 0.3839162088931318),\n",
       " ('2289', 0.3837820327329677),\n",
       " ('750', 0.3837548385321324),\n",
       " ('1090', 0.38354699181570384),\n",
       " ('1022', 0.3835287286687736),\n",
       " ('2985', 0.382646311127087),\n",
       " ('1608', 0.38257071980032076),\n",
       " ('1219', 0.3824804861872689),\n",
       " ('1376', 0.38240259468511284),\n",
       " ('2706', 0.3818071649213891),\n",
       " ('2761', 0.3812927051283921),\n",
       " ('349', 0.38097837645537314),\n",
       " ('1060', 0.38087400399033444),\n",
       " ('3608', 0.3804884625847628),\n",
       " ('586', 0.37997228452595594),\n",
       " ('912', 0.37964863607835503),\n",
       " ('3527', 0.3796381284871375),\n",
       " ('1569', 0.3794430714564796),\n",
       " ('745', 0.3791832116213218),\n",
       " ('474', 0.3783495567550915),\n",
       " ('1674', 0.37801906601592994),\n",
       " ('2018', 0.3775719879183386),\n",
       " ('596', 0.3773825412198906),\n",
       " ('368', 0.3769770076488417),\n",
       " ('1246', 0.3767167741822901),\n",
       " ('1206', 0.3763563246545722),\n",
       " ('3256', 0.37519147307859846),\n",
       " ('2124', 0.37479525010449544),\n",
       " ('1732', 0.3747404164843118),\n",
       " ('2006', 0.37418482827913496),\n",
       " ('3481', 0.3737401640361612),\n",
       " ('2424', 0.37366355742629176),\n",
       " ('1302', 0.37223114911140137),\n",
       " ('3499', 0.3718971713434626),\n",
       " ('1208', 0.37165908254363444),\n",
       " ('104', 0.3712345867468246),\n",
       " ('736', 0.37068672486380705),\n",
       " ('2502', 0.3704032992036028),\n",
       " ('2087', 0.3702600753044891),\n",
       " ('2137', 0.36867000216849133),\n",
       " ('441', 0.368436674394487),\n",
       " ('1247', 0.3682936721493008),\n",
       " ('316', 0.36811335060656625),\n",
       " ('1653', 0.3677684988727321),\n",
       " ('1639', 0.3672180999732678),\n",
       " ('1625', 0.36678475933892485),\n",
       " ('1380', 0.3663248665804517),\n",
       " ('2001', 0.36618313736447516),\n",
       " ('3247', 0.3660829581986364),\n",
       " ('2529', 0.36562094545392926),\n",
       " ('2003', 0.365303354597933),\n",
       " ('2', 0.36484464535608724),\n",
       " ('2096', 0.3640916999293541),\n",
       " ('10', 0.3636960395169369),\n",
       " ('1917', 0.3636619309193636),\n",
       " ('3809', 0.36322718909147744),\n",
       " ('953', 0.3630248619030275),\n",
       " ('1722', 0.3609867324192618),\n",
       " ('543', 0.3593872742323288),\n",
       " ('2085', 0.35924791319707927),\n",
       " ('1673', 0.3591996692515713),\n",
       " ('497', 0.35877464082932087),\n",
       " ('1909', 0.35859481084574235),\n",
       " ('1407', 0.35844199902727175),\n",
       " ('2687', 0.35825914419018934),\n",
       " ('2150', 0.3582542270584001),\n",
       " ('337', 0.35806605579082407),\n",
       " ('2683', 0.3570161265834344),\n",
       " ('2671', 0.35667648638791566),\n",
       " ('317', 0.3565838482269304),\n",
       " ('2746', 0.35530827154517275),\n",
       " ('1552', 0.3549394652163135),\n",
       " ('2968', 0.3543294832723483),\n",
       " ('231', 0.3540563969248258),\n",
       " ('1391', 0.35392203204802253),\n",
       " ('165', 0.35388540581672806),\n",
       " ('1094', 0.35328072793073884),\n",
       " ('904', 0.3532678439326739),\n",
       " ('2617', 0.3530825791402171),\n",
       " ('2359', 0.35278744071774065),\n",
       " ('1042', 0.3527293014319789),\n",
       " ('908', 0.3525299274797463),\n",
       " ('1372', 0.35252305751925656),\n",
       " ('161', 0.35251988634723896),\n",
       " ('923', 0.3522368939366514),\n",
       " ('1223', 0.35218508594764275),\n",
       " ('1912', 0.35208957080303227),\n",
       " ('2352', 0.351131113867689),\n",
       " ('2539', 0.3510478818973494),\n",
       " ('1566', 0.35059441246049194),\n",
       " ('3033', 0.34997198767453197),\n",
       " ('1408', 0.3493181038788527),\n",
       " ('3107', 0.3490232547782155),\n",
       " ('1207', 0.3489628672082281),\n",
       " ('1032', 0.34854120633844177),\n",
       " ('2947', 0.3483047794244216),\n",
       " ('339', 0.348207859691019),\n",
       " ('3450', 0.34779647695244265),\n",
       " ('454', 0.34770385815083066),\n",
       " ('3072', 0.3470644386925375),\n",
       " ('788', 0.34694060176781727),\n",
       " ('1276', 0.3467142301801877),\n",
       " ('2273', 0.34620808080006976),\n",
       " ('300', 0.34580622078972795),\n",
       " ('2161', 0.3456417616908425),\n",
       " ('2657', 0.34523254543582793),\n",
       " ('2005', 0.3449954393131207),\n",
       " ('2699', 0.3448357219414827),\n",
       " ('529', 0.3444702340120897),\n",
       " ('1994', 0.3440456413252712),\n",
       " ('6', 0.3438138294320863),\n",
       " ('1676', 0.34379196935489664),\n",
       " ('2064', 0.34346881616790614),\n",
       " ('111', 0.34311766164062396),\n",
       " ('329', 0.3421250893804122),\n",
       " ('2193', 0.3417430630867044),\n",
       " ('708', 0.3417252665584734),\n",
       " ('344', 0.34172370360531734),\n",
       " ('293', 0.3416335416549317),\n",
       " ('3087', 0.3411471452655557),\n",
       " ('3386', 0.3409264230867154),\n",
       " ('920', 0.34008362506582807),\n",
       " ('3081', 0.3398537020441346),\n",
       " ('36', 0.3388154635894692),\n",
       " ('1748', 0.3383888390142718),\n",
       " ('2795', 0.3383240272436449),\n",
       " ('2105', 0.3382657349482813),\n",
       " ('910', 0.3382577668460595),\n",
       " ('3408', 0.33824193153989607),\n",
       " ('2278', 0.33818417243087917),\n",
       " ('1215', 0.3375549102330381),\n",
       " ('1883', 0.33715485239784526),\n",
       " ('1230', 0.33673583955531916),\n",
       " ('3104', 0.3365351801455425),\n",
       " ('3105', 0.33515696125732686),\n",
       " ('1231', 0.3347676031631504),\n",
       " ('2109', 0.33366798677251824),\n",
       " ('661', 0.33358981855399816),\n",
       " ('2167', 0.33270917294130437),\n",
       " ('253', 0.33255885119352063),\n",
       " ('1375', 0.3323790873196155),\n",
       " ('2391', 0.33234142033777725),\n",
       " ('2641', 0.3322956542820174),\n",
       " ('2371', 0.3320559667413668),\n",
       " ('1035', 0.3315157706438217),\n",
       " ('852', 0.33099447739257876),\n",
       " ('903', 0.33090870067409556),\n",
       " ('2002', 0.3307932112465598),\n",
       " ('2763', 0.3305667520991199),\n",
       " ('3897', 0.33039542959365076),\n",
       " ('471', 0.33036754764267184),\n",
       " ('1275', 0.32975174693254783),\n",
       " ('2393', 0.32937847723991037),\n",
       " ('1597', 0.329277283473617),\n",
       " ('3702', 0.32924870678678586),\n",
       " ('3868', 0.32918263018175475),\n",
       " ('3006', 0.32904616343639237),\n",
       " ('2134', 0.32888995827048717),\n",
       " ('3424', 0.32872767554539667),\n",
       " ('1250', 0.32861701452709235),\n",
       " ('783', 0.32861409045761314),\n",
       " ('1876', 0.32831307266724935),\n",
       " ('3489', 0.328306244013135),\n",
       " ('3082', 0.32803634423224337),\n",
       " ('2058', 0.32795663669996916),\n",
       " ('3699', 0.3277545986299459),\n",
       " ('1997', 0.3275966544085419),\n",
       " ('3623', 0.32755780809966784),\n",
       " ('2329', 0.32720344054313977),\n",
       " ('3703', 0.3270707072251388),\n",
       " ('3698', 0.3257026124869463),\n",
       " ('3591', 0.32554221930367977),\n",
       " ('1947', 0.324920546939343),\n",
       " ('2455', 0.3245181379490575),\n",
       " ('2140', 0.32444932843283397),\n",
       " ('1729', 0.3241442050212451),\n",
       " ('2139', 0.3235733432389178),\n",
       " ('2692', 0.3233062547772015),\n",
       " ('1199', 0.32327968710941457),\n",
       " ('3504', 0.32327050096458404),\n",
       " ('1201', 0.3220171493456227),\n",
       " ('292', 0.3218674606221602),\n",
       " ('3034', 0.32178097151723134),\n",
       " ('2243', 0.3212298280707036),\n",
       " ('1257', 0.3212039005076954),\n",
       " ('1252', 0.3209787648840902),\n",
       " ('25', 0.3209509679211512),\n",
       " ('2770', 0.32079485180066913),\n",
       " ('2094', 0.3207342685378236),\n",
       " ('2145', 0.3206318041305852),\n",
       " ('17', 0.32040686050379974),\n",
       " ('778', 0.3203841216437853),\n",
       " ('3753', 0.31982548041815173),\n",
       " ('2405', 0.3197908061464831),\n",
       " ('2542', 0.31956242166868776),\n",
       " ('720', 0.31926359843085594),\n",
       " ('2423', 0.3190978884520839),\n",
       " ('1333', 0.31883235370244634),\n",
       " ('1885', 0.31872530633058055),\n",
       " ('3060', 0.31814342378122185),\n",
       " ('899', 0.31811249852816775),\n",
       " ('180', 0.3180540869158212),\n",
       " ('1967', 0.31774420194641423),\n",
       " ('353', 0.31771209935658995),\n",
       " ('2501', 0.3176826427176955),\n",
       " ('1343', 0.31742378870402915),\n",
       " ('246', 0.31620948642689134),\n",
       " ('3397', 0.31607347092786864),\n",
       " ('1544', 0.31601273717507466),\n",
       " ('3263', 0.31596612725540507),\n",
       " ('1962', 0.3157110800849088),\n",
       " ('1188', 0.31546181240976373),\n",
       " ('2384', 0.3145311910286007),\n",
       " ('3176', 0.31446314155281235),\n",
       " ('1092', 0.3135925346333643),\n",
       " ('1183', 0.313464471770477),\n",
       " ('3362', 0.31280679762922636),\n",
       " ('1235', 0.3127916056875385),\n",
       " ('1405', 0.31153208310857833),\n",
       " ('832', 0.31150206513820394),\n",
       " ('553', 0.3113778657817617),\n",
       " ('2141', 0.3107456604637884),\n",
       " ('2300', 0.31026938395534903),\n",
       " ('112', 0.3094858705418402),\n",
       " ('2133', 0.3087628389893135),\n",
       " ('1025', 0.30869247606010647),\n",
       " ('1020', 0.30761958275166373),\n",
       " ('2336', 0.3075970582210505),\n",
       " ('62', 0.3071475584169756),\n",
       " ('3098', 0.306921751491258),\n",
       " ('3740', 0.30688733059517737),\n",
       " ('969', 0.3065111246589053),\n",
       " ('3360', 0.306151223137474),\n",
       " ('508', 0.30604021280655996),\n",
       " ('1466', 0.30563703010122356),\n",
       " ('1645', 0.30530928154324055),\n",
       " ('2723', 0.3052058361329917),\n",
       " ('1233', 0.30488609770695374),\n",
       " ('1476', 0.30483054142617516),\n",
       " ('1805', 0.3044667469527666),\n",
       " ('16', 0.30395497296872287),\n",
       " ('1204', 0.3038001325673595),\n",
       " ('3160', 0.3036963010953032),\n",
       " ('1271', 0.3034404848064095),\n",
       " ('1179', 0.3028586982226347),\n",
       " ('1292', 0.30267310612988385),\n",
       " ('1953', 0.30251652101557136),\n",
       " ('1371', 0.3023946241433558),\n",
       " ('1262', 0.3023906669196578),\n",
       " ('3100', 0.30211111657892264),\n",
       " ('3763', 0.3018763163032628),\n",
       " ('2944', 0.30164614835650744),\n",
       " ('1441', 0.30080277811342554),\n",
       " ('1297', 0.3003850125736876),\n",
       " ('914', 0.3003326034045551),\n",
       " ('2948', 0.30023107924934417),\n",
       " ('1077', 0.3000431003522086),\n",
       " ('785', 0.2999408543847141),\n",
       " ('333', 0.29988920411245623),\n",
       " ('3398', 0.29966019568289737),\n",
       " ('1378', 0.2995439525690632),\n",
       " ('3755', 0.29941378746669367),\n",
       " ('3948', 0.29925550351326663),\n",
       " ('2020', 0.2989705703249719),\n",
       " ('1287', 0.29892826582327087),\n",
       " ('2366', 0.2987353939455062),\n",
       " ('2046', 0.29843340965783305),\n",
       " ('2420', 0.29831301380531067),\n",
       " ('653', 0.2980940129689815),\n",
       " ('2580', 0.29806180708175417),\n",
       " ('2871', 0.29798858642591997),\n",
       " ('552', 0.2978674201721296),\n",
       " ('3624', 0.29770215556252433),\n",
       " ('1614', 0.2976495222493026),\n",
       " ('2394', 0.29740578206078516),\n",
       " ('1918', 0.29688492229176766),\n",
       " ('3174', 0.29667703853411065),\n",
       " ('151', 0.29658058092802797),\n",
       " ('2478', 0.2959211160608399),\n",
       " ('1293', 0.2957961756072111),\n",
       " ('1272', 0.29558284541021224),\n",
       " ('3020', 0.29528299215252046),\n",
       " ('3264', 0.29477531620987557),\n",
       " ('1129', 0.2947552657149091),\n",
       " ('555', 0.2944234280344045),\n",
       " ('1256', 0.2940257718794515),\n",
       " ('2245', 0.29388321989997235),\n",
       " ('153', 0.2930858466407823),\n",
       " ('3614', 0.29296180966797936),\n",
       " ('7', 0.29288449928815563),\n",
       " ('52', 0.29287868150126956),\n",
       " ('1711', 0.2923098026869574),\n",
       " ('2872', 0.29220567320964924),\n",
       " ('1921', 0.292103319807186),\n",
       " ('3044', 0.29202515050007277),\n",
       " ('1249', 0.2915587468936122),\n",
       " ('45', 0.2914234064208892),\n",
       " ('1958', 0.2906068274484363),\n",
       " ('3555', 0.2905623671896783),\n",
       " ('3101', 0.29043023773651694),\n",
       " ('3510', 0.29024353594942953),\n",
       " ('2469', 0.2900813712503304),\n",
       " ('3254', 0.2900041190716061),\n",
       " ('673', 0.28989429054467847),\n",
       " ('2413', 0.2897957817015709),\n",
       " ('2463', 0.2892865917852609),\n",
       " ('342', 0.28920700655532644),\n",
       " ('2857', 0.2889260474058461),\n",
       " ('1449', 0.2882326391973028),\n",
       " ('1339', 0.2880446093397635),\n",
       " ('48', 0.2878909968262986),\n",
       " ('2788', 0.28773756476777534),\n",
       " ('1033', 0.2876612521420564),\n",
       " ('1320', 0.28722945913523906),\n",
       " ('3148', 0.2872294431496329),\n",
       " ('913', 0.28705741722574196),\n",
       " ('2021', 0.28688063865434443),\n",
       " ('434', 0.28685486624025447),\n",
       " ('70', 0.2865912169989936),\n",
       " ('3261', 0.2856443405618938),\n",
       " ('1960', 0.28553045054942),\n",
       " ('3358', 0.2853706130078005),\n",
       " ('2616', 0.2851994208925035),\n",
       " ('288', 0.2842969262374133),\n",
       " ('2710', 0.28407285123181664),\n",
       " ('1321', 0.28385286501917123),\n",
       " ('2949', 0.2837953007491011),\n",
       " ('647', 0.2837447030537425),\n",
       " ('1172', 0.2837371060727928),\n",
       " ('1513', 0.283694667263198),\n",
       " ('514', 0.28367494868258475),\n",
       " ('163', 0.28366102333408516),\n",
       " ('2717', 0.28295636494332876),\n",
       " ('1263', 0.2822064103015153),\n",
       " ('265', 0.28212089355728387),\n",
       " ('2572', 0.281457410830973),\n",
       " ('3000', 0.2811266771207547),\n",
       " ('1095', 0.2809869533513397),\n",
       " ('1084', 0.28094363012581486),\n",
       " ('3524', 0.2804704206950812),\n",
       " ('410', 0.2800659003116055),\n",
       " ('1587', 0.2799515696614902),\n",
       " ('1228', 0.2797989667130676),\n",
       " ('3070', 0.27965007896774613),\n",
       " ('3246', 0.27964541659044684),\n",
       " ('1267', 0.279614899421704),\n",
       " ('1269', 0.27933452664820685),\n",
       " ('466', 0.2789200582460264),\n",
       " ('509', 0.27884818572049497),\n",
       " ('442', 0.27784446124199985),\n",
       " ('2496', 0.27766462341760983),\n",
       " ('838', 0.27760471480578897),\n",
       " ('1957', 0.27755618017814015),\n",
       " ('95', 0.277467235589674),\n",
       " ('3543', 0.2773936484148556),\n",
       " ('3252', 0.27739043701154253),\n",
       " ('1059', 0.27708399021670055),\n",
       " ('3911', 0.27614712514652057),\n",
       " ('610', 0.2757295208033544),\n",
       " ('372', 0.27569177060796063),\n",
       " ('585', 0.2755027302695291),\n",
       " ('562', 0.27550168142969333),\n",
       " ('671', 0.27549674695637977),\n",
       " ('1088', 0.27532619068696584),\n",
       " ('1135', 0.2753081218081565),\n",
       " ('800', 0.27524094128159016),\n",
       " ('1120', 0.27517695355758043),\n",
       " ('2125', 0.2748187281342619),\n",
       " ('252', 0.2744492091827787),\n",
       " ('2089', 0.27362468149135144),\n",
       " ('1244', 0.2727977357881894),\n",
       " ('3037', 0.272546471170273),\n",
       " ('628', 0.27240756662204),\n",
       " ('3476', 0.27232748207918867),\n",
       " ('802', 0.2722361107568208),\n",
       " ('3479', 0.27183267668774913),\n",
       " ('3507', 0.2715006416662709),\n",
       " ('348', 0.2708877915281935),\n",
       " ('1845', 0.27076369235781345),\n",
       " ('1203', 0.2706612737049984),\n",
       " ('3088', 0.2704272219155113),\n",
       " ('3869', 0.2703909770828251),\n",
       " ('3704', 0.27029238060754274),\n",
       " ('2735', 0.2700750163740685),\n",
       " ('208', 0.26987908815286565),\n",
       " ('898', 0.2697818712673558),\n",
       " ('2908', 0.2696431463554015),\n",
       " ('1678', 0.2694100911900351),\n",
       " ('1688', 0.2693822449478246),\n",
       " ('1299', 0.26899861116553886),\n",
       " ('2581', 0.2688842784298145),\n",
       " ('3178', 0.26885974102648313),\n",
       " ('1274', 0.2684724973627535),\n",
       " ('1965', 0.26843213369034924),\n",
       " ('1023', 0.26836946079553226),\n",
       " ('3536', 0.26803749363763585),\n",
       " ('1588', 0.26788300904063195),\n",
       " ('2335', 0.2678449962739373),\n",
       " ('1345', 0.2674176881944551),\n",
       " ('350', 0.2672800330578934),\n",
       " ('616', 0.2671434797379862),\n",
       " ('2528', 0.2668887437079851),\n",
       " ('198', 0.26647402004950604),\n",
       " ('60', 0.26631182064565373),\n",
       " ('3438', 0.2662906575261594),\n",
       " ('1261', 0.2660206952650082),\n",
       " ('2083', 0.26597435605449377),\n",
       " ('2090', 0.26593506949481976),\n",
       " ('2082', 0.2655221575105028),\n",
       " ('2076', 0.2650537846776194),\n",
       " ('3712', 0.26478286507200355),\n",
       " ('2694', 0.2646772639537708),\n",
       " ('2863', 0.2645130639816286),\n",
       " ('866', 0.2645025751936436),\n",
       " ('1357', 0.2644715847184835),\n",
       " ('1479', 0.2641928695866441),\n",
       " ('1186', 0.2641214921236551),\n",
       " ('2427', 0.2639320570126984),\n",
       " ('2567', 0.26393060176834515),\n",
       " ('224', 0.2633848128367076),\n",
       " ('1952', 0.2632250375290421),\n",
       " ('2739', 0.2631988446798276),\n",
       " ('3267', 0.26283491354997324),\n",
       " ('3686', 0.2626643053660562),\n",
       " ('3745', 0.26233886163067477),\n",
       " ('1955', 0.2623287073709252),\n",
       " ('2490', 0.2620300222128408),\n",
       " ('3683', 0.26160207102459343),\n",
       " ('3269', 0.2614208270325187),\n",
       " ('1367', 0.26121190675706235),\n",
       " ('3638', 0.2611781077057822),\n",
       " ('3213', 0.26088790696389125),\n",
       " ('2065', 0.26065240296995906),\n",
       " ('2378', 0.2604361526735049),\n",
       " ('3301', 0.25996222253023066),\n",
       " ('1894', 0.2596751675854864),\n",
       " ('3635', 0.25949730653155195),\n",
       " ('902', 0.2591120752186508),\n",
       " ('1834', 0.25892635467031383),\n",
       " ('2023', 0.2588404614644215),\n",
       " ('1030', 0.25836424546235753),\n",
       " ('1586', 0.2582658514012257),\n",
       " ('1831', 0.2582601407172352),\n",
       " ('125', 0.25825267558041765),\n",
       " ('1690', 0.25812976415633176),\n",
       " ('2926', 0.2579926822404772),\n",
       " ('1982', 0.25790056626250735),\n",
       " ('3168', 0.2576032744446551),\n",
       " ('2431', 0.25754406878905417),\n",
       " ('2779', 0.2574596841429557),\n",
       " ('3159', 0.25730276842700023),\n",
       " ('1589', 0.2571583846243569),\n",
       " ('531', 0.2569550349139661),\n",
       " ('1635', 0.2567156048737869),\n",
       " ('2301', 0.2566513314910189),\n",
       " ('69', 0.25657079223592744),\n",
       " ('162', 0.25574700688675034),\n",
       " ('3359', 0.255744383361118),\n",
       " ('2414', 0.25564325596471676),\n",
       " ('1680', 0.25537775665638496),\n",
       " ('2313', 0.2552613778869102),\n",
       " ('1027', 0.25508143782712683),\n",
       " ('2288', 0.2550237659750973),\n",
       " ('3259', 0.25479938632721877),\n",
       " ('3863', 0.25421495376638764),\n",
       " ('3701', 0.25416863479834456),\n",
       " ('345', 0.25410776201639557),\n",
       " ('786', 0.25375122623103435),\n",
       " ('2398', 0.2536143227798878),\n",
       " ('2759', 0.2536143227798878),\n",
       " ('994', 0.2535085607805307),\n",
       " ('3095', 0.2532899612709744),\n",
       " ('2662', 0.2532849601299639),\n",
       " ('2664', 0.2532013399336467),\n",
       " ('3685', 0.25305510318091123),\n",
       " ('216', 0.25274301623994383),\n",
       " ('1920', 0.25249204372189066),\n",
       " ('2231', 0.25243608054992245),\n",
       " ('1047', 0.25242920912203787),\n",
       " ('784', 0.2519622561828905),\n",
       " ('2989', 0.25172471736667684),\n",
       " ('520', 0.25167223155106166),\n",
       " ('524', 0.25155021757438906),\n",
       " ('2409', 0.25147575791352494),\n",
       " ('1012', 0.2512881940274246),\n",
       " ('2019', 0.25107273924406276),\n",
       " ('2993', 0.2510561246391589),\n",
       " ('954', 0.2509047798591125),\n",
       " ('1411', 0.25089196621550997),\n",
       " ('266', 0.2507290955694599),\n",
       " ('2991', 0.2507132682112035),\n",
       " ('3429', 0.250392284817836),\n",
       " ('1537', 0.25028930628795404),\n",
       " ('2527', 0.24995378500746168),\n",
       " ('494', 0.2495759114843024),\n",
       " ('2297', 0.24940088855665973),\n",
       " ('1081', 0.24924424024012268),\n",
       " ('1385', 0.24852506087385423),\n",
       " ('1347', 0.24852506087385423),\n",
       " ('2917', 0.2485142573366467),\n",
       " ('2118', 0.24837495799794118),\n",
       " ('2951', 0.24800993643688668),\n",
       " ('1013', 0.24800993643688665),\n",
       " ('1017', 0.24791191472036486),\n",
       " ('185', 0.24783182364936604),\n",
       " ('3040', 0.24779649064341852),\n",
       " ('933', 0.2476579955475306),\n",
       " ('3317', 0.24759448762650252),\n",
       " ('805', 0.24751727744054342),\n",
       " ('1125', 0.24741232213221948),\n",
       " ('1810', 0.24720973751247674),\n",
       " ('1031', 0.2472070263334219),\n",
       " ('3441', 0.24677709814772678),\n",
       " ('2605', 0.24668080393844902),\n",
       " ('1253', 0.24656452112941427),\n",
       " ('2686', 0.2463361148542403),\n",
       " ('1124', 0.24628299444236632),\n",
       " ('1243', 0.24600924361740042),\n",
       " ('2403', 0.24509473387126982),\n",
       " ('435', 0.2450384860570331),\n",
       " ('1268', 0.24496376543646528),\n",
       " ('2728', 0.24495148193311364),\n",
       " ('3525', 0.24494897427831783),\n",
       " ('3274', 0.2448308324098832),\n",
       " ('3271', 0.2447158599070198),\n",
       " ('1694', 0.2445622203277736),\n",
       " ('2724', 0.24447125461285588),\n",
       " ('2015', 0.24446307517077343),\n",
       " ('3157', 0.24445370566468813),\n",
       " ('1672', 0.24428274894770421),\n",
       " ('1037', 0.2442436708703706),\n",
       " ('370', 0.24422996511908396),\n",
       " ('1713', 0.24419810820189153),\n",
       " ('3035', 0.24384310418680996),\n",
       " ('2792', 0.24382316430096515),\n",
       " ('2990', 0.2431124820525797),\n",
       " ('1224', 0.2430915983325136),\n",
       " ('3257', 0.24280064478919294),\n",
       " ('955', 0.2426185343566472),\n",
       " ('2712', 0.24257217002103035),\n",
       " ('1914', 0.24253562503633297),\n",
       " ('2111', 0.24242006870705685),\n",
       " ('3260', 0.24229743287334163),\n",
       " ('1754', 0.24228214326003303),\n",
       " ('1049', 0.24210175478196827),\n",
       " ('663', 0.24207630814917877),\n",
       " ('1104', 0.24135257162455764),\n",
       " ('1091', 0.24111205091626262),\n",
       " ('741', 0.24084948531452416),\n",
       " ('2375', 0.24084744266174826),\n",
       " ('1298', 0.24075908918333744),\n",
       " ('1019', 0.23982252250478184),\n",
       " ('2138', 0.23980605589610213),\n",
       " ('2312', 0.2397583709344077),\n",
       " ('1717', 0.2396440286136101),\n",
       " ('1956', 0.23957509556524095),\n",
       " ('2110', 0.23946644458502275),\n",
       " ('515', 0.23934470555635626),\n",
       " ('2160', 0.23932387483364617),\n",
       " ('1103', 0.2393172105652397),\n",
       " ('3451', 0.2393043381659853),\n",
       " ('1015', 0.23920508390280598),\n",
       " ('2116', 0.2391601312699459),\n",
       " ('2648', 0.23870495007747403),\n",
       " ('1093', 0.23841306956285366),\n",
       " ('1945', 0.23804969802576675),\n",
       " ('1409', 0.23766464347609784),\n",
       " ('3697', 0.23761656233403355),\n",
       " ('2421', 0.23676013879409538),\n",
       " ('2794', 0.2366595697156244),\n",
       " ('2143', 0.236460054556202),\n",
       " ('799', 0.2364001617942559),\n",
       " ('909', 0.2363750255618381),\n",
       " ('3505', 0.23597839012127703),\n",
       " ('22', 0.23597271244596968),\n",
       " ('2973', 0.23586475766431486),\n",
       " ('2369', 0.23583307948485588),\n",
       " ('2059', 0.23582238045179515),\n",
       " ('24', 0.23566599571949606),\n",
       " ('3639', 0.2356240471360787),\n",
       " ('236', 0.23547940345293353),\n",
       " ('2467', 0.23546839328965277),\n",
       " ('158', 0.23536270816678753),\n",
       " ('107', 0.23509055184666092),\n",
       " ('1171', 0.23503179865860077),\n",
       " ('2416', 0.23493409682450583),\n",
       " ('2747', 0.2347710325453716),\n",
       " ('3893', 0.23474276701672123),\n",
       " ('2841', 0.23425953148140555),\n",
       " ('2067', 0.23421601750764798),\n",
       " ('3071', 0.2341959786380979),\n",
       " ('2565', 0.23407491596158),\n",
       " ('2912', 0.23377160793775684),\n",
       " ('1296', 0.23375009103391972),\n",
       " ('1792', 0.23373835947412475),\n",
       " ('2311', 0.23366910364872803),\n",
       " ('29', 0.23365775387507676),\n",
       " ('1373', 0.23365775387507676),\n",
       " ('3250', 0.23359756707604765),\n",
       " ('1895', 0.23342003725709462),\n",
       " ('2803', 0.23335217464183175),\n",
       " ('915', 0.23321081286465734),\n",
       " ('1185', 0.2332002421550554),\n",
       " ('748', 0.23266194133843296),\n",
       " ('247', 0.23238146825637976),\n",
       " ('58', 0.23216508698566796),\n",
       " ('3', 0.23196289500859177),\n",
       " ('905', 0.23196057104977805),\n",
       " ('3551', 0.23164099827822648),\n",
       " ('724', 0.23099064380279552),\n",
       " ('1620', 0.2308895165384345),\n",
       " ('1892', 0.23060637521878097),\n",
       " ('837', 0.23039025658579906),\n",
       " ('3508', 0.23035028448268424),\n",
       " ('2881', 0.23033870940992868),\n",
       " ('916', 0.22997820668516017),\n",
       " ('485', 0.22956218151238),\n",
       " ('861', 0.22951105567123486),\n",
       " ('3827', 0.22945614846736817),\n",
       " ('2253', 0.228747855498907),\n",
       " ('2518', 0.22869451480602285),\n",
       " ('145', 0.22839891633269513),\n",
       " ('3735', 0.22838126928013197),\n",
       " ('379', 0.22808028971548822),\n",
       " ('1245', 0.2276489554573469),\n",
       " ('2946', 0.22758952629943893),\n",
       " ('2088', 0.22757972475669258),\n",
       " ('2883', 0.22757972475669258),\n",
       " ('450', 0.22728930420828566),\n",
       " ('3916', 0.22696089971622865),\n",
       " ('3466', 0.2269475299428268),\n",
       " ('196', 0.2267697101124871),\n",
       " ('2622', 0.2264380567581057),\n",
       " ('3249', 0.22633442673900211),\n",
       " ('2333', 0.22630960592924257),\n",
       " ('1693', 0.22625),\n",
       " ('272', 0.22599810731214215),\n",
       " ('507', 0.22589738739000423),\n",
       " ('3791', 0.2258973107754413),\n",
       " ('1010', 0.22578069686517285),\n",
       " ('3435', 0.22571125792861896),\n",
       " ('830', 0.22565281278812352),\n",
       " ('101', 0.22559411309398333),\n",
       " ('1701', 0.22558619291699264),\n",
       " ('376', 0.225566579284567),\n",
       " ('3785', 0.2255555488642917),\n",
       " ('1562', 0.22516660498395405),\n",
       " ('968', 0.22510425786799104),\n",
       " ('5', 0.22469605638953555),\n",
       " ('3019', 0.22450233562548677),\n",
       " ('2433', 0.22415566624973907),\n",
       " ('2826', 0.22407354869301419),\n",
       " ('1616', 0.22388798050491576),\n",
       " ('921', 0.2234542865595068),\n",
       " ('3723', 0.223445742854949),\n",
       " ('2919', 0.22324298800631806),\n",
       " ('2112', 0.22322093586152836),\n",
       " ('1254', 0.22310147100745098),\n",
       " ('951', 0.22305857572648538),\n",
       " ('1689', 0.22298078416654402),\n",
       " ('986', 0.22278576064378772),\n",
       " ('144', 0.22263552296737493),\n",
       " ('2126', 0.2226012679732783),\n",
       " ('2447', 0.22200960633747913),\n",
       " ('468', 0.2219771420441889),\n",
       " ('1100', 0.22188007849009164),\n",
       " ('2376', 0.2216891233591092),\n",
       " ('1835', 0.2211969036298623),\n",
       " ('432', 0.22111062447761468),\n",
       " ('2247', 0.22073657984384784),\n",
       " ('3770', 0.22057470084576483),\n",
       " ('2690', 0.2205531186832767),\n",
       " ('1779', 0.22039303460181467),\n",
       " ('431', 0.22014317557326024),\n",
       " ('3068', 0.22000554316741713),\n",
       " ('1429', 0.22),\n",
       " ('3258', 0.21971768720102058),\n",
       " ('1283', 0.21965882636488795),\n",
       " ('1619', 0.21950492118276702),\n",
       " ('2013', 0.21944918301336563),\n",
       " ('2249', 0.2193914234537961),\n",
       " ('1801', 0.21939062508870244),\n",
       " ('2410', 0.21923215467304413),\n",
       " ('303', 0.2191049260996087),\n",
       " ('3798', 0.2186327499017678),\n",
       " ('2282', 0.21840329667841554),\n",
       " ('900', 0.21830630616659225),\n",
       " ('1061', 0.2183011328770069),\n",
       " ('1350', 0.21815580217584976),\n",
       " ('2146', 0.2181367532596847),\n",
       " ('1041', 0.21795512058632724),\n",
       " ('517', 0.21761365926335272),\n",
       " ('1217', 0.2175832841675411),\n",
       " ('934', 0.21748814885071543),\n",
       " ('2099', 0.21747825510576974),\n",
       " ('3468', 0.2170558193174087),\n",
       " ('2953', 0.21702826042427012),\n",
       " ('2867', 0.21661908532029212),\n",
       " ('1248', 0.21639356706963508),\n",
       " ('1078', 0.21638116657545525),\n",
       " ('1702', 0.21634470515023216),\n",
       " ('1884', 0.21615323782497967),\n",
       " ('3334', 0.21537225845736094),\n",
       " ('930', 0.21524735078125498),\n",
       " ('3298', 0.2152200922524702),\n",
       " ('1009', 0.21514114968019085),\n",
       " ('361', 0.21487921473022215),\n",
       " ('3265', 0.21463021463032195),\n",
       " ('2102', 0.21457138789490238),\n",
       " ('1719', 0.2144890569599194),\n",
       " ('3462', 0.21423727715199728),\n",
       " ('1518', 0.2141729809977759),\n",
       " ('922', 0.21407291707008191),\n",
       " ('1379', 0.21397462597758876),\n",
       " ('230', 0.21394879382398385),\n",
       " ('1096', 0.21384070730631674),\n",
       " ('3545', 0.21376670117594454),\n",
       " ('322', 0.21371868349696446),\n",
       " ('1888', 0.21364993867608834),\n",
       " ('475', 0.21350981400855115),\n",
       " ('1277', 0.213431350031973),\n",
       " ('170', 0.21341745136471044),\n",
       " ('1238', 0.21341679636795838),\n",
       " ('2334', 0.21324152314856382),\n",
       " ('538', 0.2131488504131149),\n",
       " ('3633', 0.21289050805766946),\n",
       " ('1086', 0.21273317890118928),\n",
       " ('926', 0.21259569832499328),\n",
       " ('3308', 0.21251121605494744),\n",
       " ('3744', 0.21249592690316987),\n",
       " ('3654', 0.2119889157751476),\n",
       " ('168', 0.21186138369613122),\n",
       " ('1873', 0.2118563590811399),\n",
       " ('1459', 0.2117738404742249),\n",
       " ('2471', 0.2117647237988755),\n",
       " ('2707', 0.2117403179938836),\n",
       " ('3615', 0.211698756813458),\n",
       " ('3477', 0.21157747357033163),\n",
       " ('1687', 0.21156578325703163),\n",
       " ('1590', 0.21156578325703163),\n",
       " ('3684', 0.2115035844466146),\n",
       " ('319', 0.21144229268822948),\n",
       " ('1303', 0.21137109751285152),\n",
       " ('2688', 0.21114358505160125),\n",
       " ('2340', 0.21113727138622648),\n",
       " ('928', 0.21102901383660747),\n",
       " ('2009', 0.210979212864371),\n",
       " ('1395', 0.21086242662684826),\n",
       " ('362', 0.21081917279529025),\n",
       " ('261', 0.21078607456558707),\n",
       " ('222', 0.21078369454558774),\n",
       " ('2401', 0.210678128842561),\n",
       " ('2474', 0.2105715813671893),\n",
       " ('1959', 0.21037247668687178),\n",
       " ('1212', 0.2101864504411371),\n",
       " ('1425', 0.21014419797273926),\n",
       " ('940', 0.21006697433136742),\n",
       " ('3196', 0.21001043174875614),\n",
       " ('3388', 0.21),\n",
       " ('2541', 0.20992917284465545),\n",
       " ('262', 0.2099125797546219),\n",
       " ('3681', 0.20988901366734855),\n",
       " ('3717', 0.20974032175691465),\n",
       " ('1591', 0.20972347446810025),\n",
       " ('2048', 0.20968983663069343),\n",
       " ('2642', 0.209410610376642),\n",
       " ('3752', 0.20936515859499608),\n",
       " ('3244', 0.2092497860762896),\n",
       " ('2155', 0.20892304135566842),\n",
       " ('2701', 0.20859864059274896),\n",
       " ('232', 0.20859864059274896),\n",
       " ('3016', 0.2083332420091124),\n",
       " ('2476', 0.20823383040466792),\n",
       " ('3300', 0.20815043436278408),\n",
       " ('3186', 0.2080832733514365),\n",
       " ('1457', 0.20775818043692418),\n",
       " ('1021', 0.20767331347143553),\n",
       " ('3668', 0.20737876550156328),\n",
       " ('2986', 0.2073221072156823),\n",
       " ('2889', 0.20714285714285716),\n",
       " ('2374', 0.20690563433717277),\n",
       " ('3243', 0.2067607312813533),\n",
       " ('351', 0.20670523249326955),\n",
       " ('172', 0.20647518010647187),\n",
       " ('3512', 0.206411994152591),\n",
       " ('2819', 0.20634564604329708),\n",
       " ('491', 0.20614846836985218),\n",
       " ('1064', 0.20599063779002882),\n",
       " ('1644', 0.20584117235211744),\n",
       " ('3706', 0.205603012794211),\n",
       " ('3730', 0.20550529507498067),\n",
       " ('2722', 0.20546966565689115),\n",
       " ('2123', 0.20541374149458744),\n",
       " ('492', 0.20540916738309434),\n",
       " ('3760', 0.20524736834716964),\n",
       " ('1950', 0.20524465579294243),\n",
       " ('2468', 0.20514131627065185),\n",
       " ('535', 0.20510549890887086),\n",
       " ('173', 0.20508555735816666),\n",
       " ('1175', 0.20493901531919195),\n",
       " ('2186', 0.20481750868616377),\n",
       " ('1284', 0.20455572617940068),\n",
       " ('428', 0.20446626032894333),\n",
       " ('2135', 0.20441373264353901),\n",
       " ('2142', 0.20435597284239976),\n",
       " ('2921', 0.20431793704418932),\n",
       " ('3535', 0.20419128029220154),\n",
       " ('1057', 0.20411064897450448),\n",
       " ('1438', 0.20409045205829504),\n",
       " ('3617', 0.2040457667353102),\n",
       " ('3836', 0.2038395491501902),\n",
       " ('2718', 0.20374718434656047),\n",
       " ('532', 0.20346142564166295),\n",
       " ('2240', 0.20319719369633615),\n",
       " ('516', 0.20316513879017703),\n",
       " ('3844', 0.20315787306251076),\n",
       " ('1963', 0.20285714285714285),\n",
       " ...]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "item_sim_score_sorted[\"1\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 取相识计算\n",
    "def cal_recom_result(sim_info,user_click):\n",
    "    recent_click_num = 3\n",
    "    topk=5\n",
    "    recom_info = {}\n",
    "    for user in user_click:\n",
    "        recom_info.setdefault(user,{})\n",
    "        click_list = user_click[user]\n",
    "        for itemid in click_list[:recent_click_num]:\n",
    "            for itemsimzuhe in sim_info[itemid][:topk]:\n",
    "                itemsimid = itemsimzuhe[0]\n",
    "                itemsimscore = itemsimzuhe[1]\n",
    "                recom_info[user][itemsimid]= itemsimscore\n",
    "    return recom_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "recom_result = cal_recom_result(item_sim_score_sorted,user_click)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'1022': 0.37946312147705386,\n",
       " '1028': 0.49163471985912854,\n",
       " '1029': 0.37439179041757437,\n",
       " '1035': 0.4952254020433806,\n",
       " '1225': 0.5118635212557388,\n",
       " '1247': 0.5148592176673679,\n",
       " '1947': 0.5832761273205334,\n",
       " '2565': 0.5060233745526537,\n",
       " '318': 0.5198255105750703,\n",
       " '364': 0.39249698357306506,\n",
       " '551': 0.40776389576686833,\n",
       " '595': 0.3971570575568227,\n",
       " '608': 0.5255996536174563,\n",
       " '858': 0.5324877380347874,\n",
       " '899': 0.525820107323753}"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "recom_result[\"1\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['West Side Story (1961)', 'Musical|Romance']\n",
      "['Toy Story (1995)', \"Animation|Children's|Comedy\"]\n",
      "[\"Singin' in the Rain (1952)\", 'Musical|Romance']\n"
     ]
    }
   ],
   "source": [
    "print(item_info['1947'])\n",
    "print(item_info['1'])\n",
    "print(item_info['899'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1082\n"
     ]
    }
   ],
   "source": [
    "print(len(item_info))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
